package 堆;

import java.util.*;

class Student implements Comparable<Student>{
    int age;
    String name ;
    public Student(int age,String name) {
        this.age = age;
        this.name = name;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Student student = (Student) o;
        return age == student.age && Objects.equals(name, student.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(age, name);
    }

    @Override
    public int compareTo(Student o) {
        //小根堆
        return this.age-o.age;
        //大根堆
        //return o.age-this.age;
    }
}
class ageComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o2.age-o1.age;
    }
}
class nameComparator implements Comparator<Student> {

    @Override
    public int compare(Student o1, Student o2) {
        return o1.name.compareTo(o2.name);
    }
}
public class Test {
    public static void main(String[] args) {
        TestHeap testHeap=new TestHeap(10);
        int[]array={27,15,19,18,28,34,35,49};
        testHeap.HeapSort(array);
        System.out.println();
    }
    public static void main2(String[] args) {
        TestHeap testHeap=new TestHeap(10);
        int[]array={27,15,19,18,28,34,35,49};
//        int[]elem= testHeap.bigK(array,3);
        int[]elem= testHeap.smallestK(array,3);
        System.out.println(Arrays.toString(elem));
    }
    public static void main3(String[] args) {
        Queue<Student> priorityQueue=new PriorityQueue<>(new ageComparator());
        priorityQueue.offer(new Student(33,"Z"));
        priorityQueue.offer(new Student(22,"L"));
        priorityQueue.offer(new Student(11,"W"));


        System.out.println( priorityQueue.peek().age+" "+priorityQueue.peek().name);
    }
    public static void main1(String[] args) {
        TestHeap testHeap=new TestHeap(10);
        int[]array={27,15,19,18,28,34,35,49};
        testHeap.initElem(array);
       // testHeap.offer(80);
        System.out.println(testHeap.pop());
        System.out.println();
    }
}
